package com.tfjybj.msg.commons.config;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @Description: 自定义实体的id策略-用雪花算法生成的id
 * @Author: xuziguo
 * @Date: 2021/4/19 下午 7:54
 * @Modified By:
 * @Modify Date:
 */
@Component
public class JPAAuditorAware implements AuditorAware<String> {
    @Override
    public Optional<String> getCurrentAuditor() {
        Snowflake snowflake= IdUtil.createSnowflake(1,1);
        String id=snowflake.nextIdStr();
        return Optional.of(id);
    }
}
